package top.melody.ecommerce.platform.handler.enums;


import top.melody.ecommerce.common.util.StringUtil;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class ApproveStatus implements Serializable{

    private static Map<String, ApproveStatus> map = new HashMap<String, ApproveStatus>();
    //默认
    public static ApproveStatus DEF = new ApproveStatus("def");
    //审核中
    public static ApproveStatus APPROVING = new ApproveStatus("approving");
    //审核通过
    public static ApproveStatus APPROVED = new ApproveStatus("approved");
    //审核失败
    public static ApproveStatus REJECTED = new ApproveStatus("rejected");

    private String code;

    private ApproveStatus() {

    }

    private ApproveStatus(String code) {
        if (!StringUtil.isEmpty(code)) {
            this.code = code.toLowerCase();
            map.put(this.code, this);
        }
    }

    public String getCode() {
        return this.code;
    }




    public static Collection<ApproveStatus> getAll() {
        return map.values();
    }

    public static ApproveStatus getByCode(String code) {
        if (!StringUtil.isEmpty(code)) {
            return map.get(code.toLowerCase());
        }
        return null;
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (obj instanceof ApproveStatus) {
            return code.equalsIgnoreCase(((ApproveStatus) obj).getCode());
        } else {
            return false;
        }
    }


    @Override
    public String toString() {
        return this.code.toString();
    }

    @Override
    public int hashCode() {
        return this.code.hashCode();
    }
}
